<!DOCTYPE html>
<html lang="en" xmlns:zxw="http://www.w3school.com.cn" xmlns:njzxw="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>首页</title>
    <link rel="stylesheet" href="../../../js/common/layui/css/layui.css">
    <link rel="stylesheet" href="../../../css/common/animate.css"/>
    <link rel="stylesheet" href="../../../css/common/common.css"/>
    <style type="text/css">
        .layui-upload-drag img {
            width: 100px;
            height: 100px;
        }

        .layui-field-title {
            border-width: 1px;
            padding: 10px;
            border-radius: 5px;
        }
    </style>
</head>
<body class="layout-zxw layout-zxw-add">

<form action="" id="form1" class="layui-form" lay-filter="form1">
    <input type="hidden" id="id" name="id" value="">
    <div class="layui-row ">
        <zxw:input id="groupname" type="text" parcel="true" placeholder="请输入类型名称" parcelName="类型名称" inline="true"
                   value="" maxlength="10" name="groupname" lay_verify="required"></zxw:input>
        <zxw:input id="groupcode" type="text" parcel="true" placeholder="请输入类型编码" parcelName="类型编码" inline="true"
                   value="" maxlength="20" name="groupcode" lay_verify="required"></zxw:input>
    </div>
    <div class="layui-row ">
        <zxw:radio id="big_type" isItem="true" url="DEPLOY.TYPE" type="text" parcel="true" placeholder="配置参数分类类型" parcelName="请选择配置参数分类类型" inline="false"
                   value="" name="big_type" field_name_key="name" field_value_key="values" lay_verify="required"></zxw:radio>
    </div>
    <div class="layui-row">
        <zxw:switch id="init" name="init" parcel="true" inline="true" text="是|否" remark="是否系统初始化"
                    parcelName="是否系统初始化"></zxw:switch>
        <zxw:switch id="siglesubitem" name="siglesubitem" change="siglesubitem_change" parcel="true" inline="true"
                    text="是|否" remark="是否多项参数值" parcelName="是否多项参数"></zxw:switch>
    </div>
    <div class="layui-row item_num_div">
        <zxw:switch id="is_add_item" name="is_add_item" parcel="true" inline="true" text="是|否" remark="是否允许添加项"
                    parcelName="是否允许添加项" change="is_add_item_change" ></zxw:switch>
        <zxw:input id="item_num" type="text" parcel="true" placeholder="请输入初始化参数数量" parcelName="参数数量"
                   parcelclass="col-xs-4" inline="true" value="1" maxlength="10" name="item_num"
                   lay_verify="number" class="is_add_item_class" ></zxw:input>
    </div>
    <div class="layui-row">
        <zxw:switch id="weixinxcx" name="weixinxcx" parcel="true" inline="true" text="是|否" remark="微信小程序是否初始化加载"
                    parcelName="小程序初始化"></zxw:switch>
        <zxw:switch id="is_reload" name="is_reload" parcel="true" inline="true" text="是|否" remark="参数值改变是否需要重启"
                    parcelName="是否需要重启"></zxw:switch>
        <zxw:switch id="is_app" name="is_app" parcel="true" inline="true" text="是|否" remark="app是否初始化加载"
                    parcelName="app初始化"></zxw:switch>
    </div>
    <div class="layui-row ">
        <zxw:select id="input_type" isItem="true" url="INPUT.VALUE.TYPE" type="text" parcel="true" remark="文本框输入的类型，如文本输入、下拉选择等" placeholder="请选择输入框类型" parcelName="输入框类型" inline="true"
                   value="" change="input_type_change" name="input_type" field_name_key="name" field_value_key="values" lay_verify="required"></zxw:select>
    </div>
    <zxw:input remark="预设值(主要针对下拉框做预设值)（格式id&name  多个使用|隔开，如：1|0&开|关）" id="preinstall_val" type="text" parcel="true" placeholder="请输入下拉框预设值" parcelName="下拉框预设值" inline="false"
               value="" maxlength="20" name="preinstall_val" ></zxw:input>
    <div class="layui-row">
        <zxw:textarea rich="false" height="400px" id="remark" type="text" parcel="true" placeholder="请输入备注"
                      parcelName="备注" parcelclass="col-xs-12" inline="false" value="" name="remark"
                      lay_verify=""></zxw:textarea>
    </div>

</form>

<script type="application/javascript" src="../../../js/common/own/own.js?layui,jquery,njzxw,URL">
    njzxw.layui.val({
        url: URL.ITEM.GETBIGMAP,
        param_name: 'groupcode',
        paramExe:function(data){

            njzxw.getItem({
                group_id:'DEPLOY.TYPE',
                async:false,
                fun:function(a){
                    for(var i=0;i<a.length;i++){
                        if(a[i].values.split('|')[0] == data.big_type){
                            data.big_type = a[i].values;
                        }
                    }
                }
            });

            own.hideLoad();

            return data;
        },
        fun: function (data) {
            if (!$.isEmptyObject(data) && data.siglesubitem == 1) {
                $('.item_num_div').show();
                if(data.is_add_item == 1){
                    $('.is_add_item_class').parents('.layui-inline').hide();
                }else{
                    $('.is_add_item_class').parents('.layui-inline').show();
                }
            } else {
                $('#preinstall_val').parents('.layui-form-item').hide();
                $('.is_add_item_class').parents('.layui-inline').hide();
                $('.item_num_div').hide();
            }
            if (!$.isEmptyObject(data)) {
                $('#id').val(data.id);
            }
            if(!$.isEmptyObject(data) && data.input_type == 2){
                $('#preinstall_val').parents('.layui-form-item').show();
            }else{
                $('#preinstall_val').parents('.layui-form-item').hide();
            }
        }
    });
    njzxw.layui.submit({
        url: URL.ITEM.SAVEBIG,
        prepFun: function (data) {
            data.id = $('#id').val();

            if(data.input_type != 2){
                data.preinstall_val = '';
            }else{
                if($.trim(data.preinstall_val) == ''){
                    return "输入框类型为下拉框项，则下拉框预设值必填";
                }
            }
            data.big_type = data.big_type.split('|')[0];

            return data;
        }
    });

    function siglesubitem_change(obj) {
        $('#item_num').val(1);
        layui.form.val("form1", {
            "is_add_item": false
        });
        if (obj) {
            $('.item_num_div').show();
            is_add_item_change(false);
        } else {
            $('.item_num_div').hide();
            is_add_item_change(false);
        }
    }

    function is_add_item_change(a){
        if(a){
            $('#item_num').val(0);
            $('.is_add_item_class').parents('.layui-inline').hide();
        }else{
            $('#item_num').val(1);
            $('.is_add_item_class').parents('.layui-inline').show();
        }
    }

    function input_type_change(a){
        if(a.value == 2){//下拉选择
            $('#preinstall_val').parents('.layui-form-item').show();
        }else{
            $('#preinstall_val').parents('.layui-form-item').hide();
        }
    }

</script>
</body>
</html>